<template>
  <div class="app-container customer-div">
    <el-menu :default-active="listQuery1.status" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="0">全部({{all}})</el-menu-item>
      <el-menu-item index="1">执行中({{lineCount}})</el-menu-item>
      <el-menu-item index="2">已过期({{outCount}})</el-menu-item>
    </el-menu>
    <!--搜索-->
    <el-form :inline="true" :model="listQuery1" size="mini" label-width="80px" style="margin-top:40px;">
      <el-form-item label="员工姓名：">
        <el-input v-model="listQuery1.userName" placeholder="请输入关键字"></el-input>
      </el-form-item>
      <el-form-item label="合同公司：">
        <el-input v-model="listQuery1.contractCompany"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          @click="handleSearchList1()"
          type="primary">
          查询
        </el-button>
        <el-button
          @click="showPop('add','')"
          type="primary">
          新增
        </el-button>
        <el-button
          @click="showImport()"
          type="primary">
          导入
        </el-button>
        <exportPop ref="exportPop" @click.native="downloadExcel"></exportPop>
      </el-form-item>
    </el-form>


    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="listLoading1"
        :data="tableData1"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          label="员工姓名"
          min-width="100"
          align="center">
          <template slot-scope="scope">
              {{scope.row.userName}}
          </template>
        </el-table-column>

        <el-table-column
          label="员工工号"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.jobNumber}}
          </template>
        </el-table-column>

        <el-table-column
          label="部门"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.departmentName}}
          </template>
        </el-table-column>

        <el-table-column
          label="岗位"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.job}}
          </template>
        </el-table-column>

        <el-table-column
          label="合同类型"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.type | fiftype}}
          </template>
        </el-table-column>

        <el-table-column
          label="合同公司"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.contractCompany}}
          </template>
        </el-table-column>

        <el-table-column
          label="合同编号"
          min-width="150"
          align="center">
          <template slot-scope="scope">
            {{scope.row.number}}
          </template>
        </el-table-column>

        <el-table-column
          label="合同期限"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.term}} 个月
          </template>
        </el-table-column>

        <el-table-column
          label="合同开始时间"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.startTime}}
          </template>
        </el-table-column>

        <el-table-column
          label="合同结束时间"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.endTime}}
          </template>
        </el-table-column>

        <el-table-column
          label="合同签订日期"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.createTime}}
          </template>
        </el-table-column>

        <el-table-column
          label="合同状态"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.status }}
          </template>
        </el-table-column>

        <el-table-column
          label="附件"
          min-width="200"
          align="center">
          <template slot-scope="scope">
              <img :src="item" v-for="item in scope.row.url" @click="fullImg(item)" style="width:30px;height:30px;object-fit: contain;cursor: pointer"/>
          </template>
        </el-table-column>


        <el-table-column
          min-width="150"
          fixed="right"
          label="操作"
          align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="mini"
              @click="showPop('edit',scope.row)">修改
            </el-button>

            <el-button
              type="text"
              size="mini"
              @click="showPop('renewal',scope.row)">续签
            </el-button>

            <el-button
              type="text"
              size="mini"
              @click="delItem(scope.row)">删除
            </el-button>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery1.pageNum"
        :page-size="listQuery1.pageSize"
        :page-sizes="[10,15,20]"
        :total="count1">
      </el-pagination>
    </div>


    <!--新增编辑续签合同-->
    <htpop ref="htpop" @getcontractList="getList1"></htpop>
    <import-pop ref="importPop" @getList="handleSearchList1"></import-pop>

    <!--放大图片-->
    <el-dialog
      :visible.sync="dialogVisibleimg"
      width="800px">
      <img :src="fullSrc" style="width:100%;"/>
    </el-dialog>

  </div>
</template>
<script>

import {contractList,updateContract,deleteContract,addContract} from '@/api/company'
import {getOrderUsersList,getQiniuToken} from '@/api/partner'
import htpop from './components/htpop.vue'
import store from '@/store'
import importPop from './components/importPop.vue'
import exportPop from './components/exportPop.vue'
import { mapGetters } from 'vuex'
const defaultListQuery={
  pageNum: 1,
  pageSize: 10,
  status: '0',
  contractCompany: '',
  userName:'',
};

export default {
  name: "index",
  components : {
    htpop:htpop,
    importPop,
    exportPop
  },
  data(){
    return {
      listQuery1: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData1: [],
      count1: 0,
      listLoading1: false,
      dialogVisibleimg:false,
      fullSrc:'',
      lineCount:'',
      outCount:'',
      all:'',
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },
  created() {
    this.listQuery1.status = this.$route.query.status ? this.$route.query.status : '0'
    this.getUserOptionList();
    this.getList1()
  },
  filters: {
    fiftype(val){
      if(val == 1){
        return '固定合同'
      }else if(val == 2){
        return '实习协议'
      }else if(val == 3){
        return '其它'
      }
    },

    fifstatus(val){
      if(val == 1){
        return '执行中'
      }else if(val == 2){
        return '失效'
      }
    },
  },
  methods:{
    //显导入弹窗
    showImport(){
      this.$refs.importPop.showImport('importContract','导入员工合同记录','/api/user/contract/download')
    },
    downloadExcel(){
      this.$refs.exportPop.downloadExcel('exportUserContract',this.listQuery1)
    },
    fullImg(src){
      this.dialogVisibleimg = true;
      this.fullSrc = src;
    },


    //获取员工下拉选项
    getUserOptionList(){
      getOrderUsersList().then((res)=>{
        this.userOptionList = res;
      })
    },

    handleSelect(key){
      this.listQuery1.status = key;
      this.handleSearchList1()
    },




    //显示弹窗
    showPop(type,item){
        let form
        if(type == 'add'){
          form = {}
        }else{
          form = JSON.parse(JSON.stringify(item))
        }
        this.$refs.htpop.showPop(type,form,'list')
    },



    delItem(item){
      this.$confirm('确认删除此记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteContract({contractId:item.contractId}).then(()=>{
          this.getList1();
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    //获取列表
    getList1() {
      this.listLoading1 = true;
      let listQuery = JSON.parse(JSON.stringify(this.listQuery1));
      contractList(listQuery).then(response => {
        this.tableData1 = response.list;
        this.count1 = response.count;
        this.listLoading1 = false;
        this.all = response.all;
        this.outCount = response.outCount;
        this.lineCount = response.lineCount
      }).catch(()=>{
        this.listLoading1 = false;
      });
    },

    handleSizeChange1(val){
      this.listQuery1.pageNum = 1;
      this.listQuery1.pageSize = val;
      this.getList1();
    },
    handleCurrentChange1(val){
      this.listQuery1.pageNum = val;
      this.getList1();
    },

    handleSearchList1(){
      this.listQuery1.pageNum = 1;
      this.getList1();
    },


  },
}
</script>

<style scoped lang="scss">

</style>
